<template>
  <div class="invoice_add">
    <van-sticky>
      <van-nav-bar title="设置" left-arrow @click-left="back" />
    </van-sticky>
    <van-cell-group>
      <van-field v-model="form.company" label="公 司" placeholder="公司名称（必填）" />
      <van-field v-model="form.taxNumber" label="税 号" placeholder="15-20位数字字母（必填）" />
      <van-field v-model="form.address" label="地 址" placeholder="公司地址" />
      <van-field v-model="form.phone" label="电话号码" placeholder="电话号码" />
      <van-field v-model="form.bank" label="开户银行" placeholder="开户银行名称" />
      <van-field v-model="form.bankAccount" label="银行账户" placeholder="银行账户号码" />
    </van-cell-group>
    <p class="tips">温馨提示请填写完整准确信息，以便开具增值税发票下次开票您只要出示上述信息即可，我们不会把您的信息用作其他用途</p>
    <div class="btn" @click="addInvoice">添加</div>
  </div>
</template>

<script>
import api from 'api/api'
export default {
  data () {
    return {
      chosenAddressId: '1',
      form: {
        address: '',
        bankAccount: '',
        bank: '',
        company: '',
        taxNumber: '',
        phone: ''
      }
    }
  },
  methods: {
    addInvoice () {
      if (!this.form.company) {
        this.$toast('请输入公司名称')
        return
      }
	  else if(!this.form.taxNumber){
		  this.$toast('税号不能为空')
		  return
	  }
	  else if(!this.form.address){
	  		  this.$toast('地址不能为空')
	  		  return
	  }
	  else if(!this.form.phone){
	  		  this.$toast('手机号不能为空')
	  		  return
	  }
	  else if(!this.form.bank){
	  		  this.$toast('开户银行不能为空')
	  		  return
	  }
	  else if(!this.form.bankAccount){
	  		  this.$toast('银行账户不能为空')
	  		  return
	  }
	  else if(!(/^1[3456789]\d{9}$/.test(this.form.phone))){
		  this.$toast('手机号输入有误')
		  return
	  }
	  else if(!(/^([1-9]{1})(\d{11}|\d{15}|\d{16}|\d{17}|\d{18})$/.test(this.form.bankAccount))){
		  this.$toast('银行卡输入有误')
		  return
		  
	  }
      api.addRise({
        data: this.form
      }).then(res => {
        this.$toast('添加成功')
        this.back()
      })
    },

    back () {
      window.history.go(-1)
    }
  }
}
</script>

<style lang="scss">
.invoice_add {
  min-height: 100vh;
  background-color: #fff;
  text-align: left;
  .btn {
    width: 6.88rem;
    height: 0.91rem;
    line-height: 0.91rem;
    text-align: center;
    background: linear-gradient(
      96deg,
      rgba(72, 143, 240, 1),
      rgba(51, 130, 239, 1)
    );
    border-radius: 0.45rem;
    margin: 0 auto;
    color: #fff;
    font-size: 0.36rem;
  }
  .tips {
    font-size: 0.22rem;
    padding: 0.3rem;
  }
  .mb_18 {
    margin-bottom: 0.18rem;
  }
  .mb_105 {
    margin-bottom: 1.05rem;
  }
}
</style>